from django.db import models

# Create your models here.


class Publisher(models.Model):
  name = models.CharField(max_length=30)
  address = models.CharField(max_length=200)
  city = models.CharField(max_length=50)
  country = models.CharField(max_length=50)
  website = models.URLField()

  def __str__(self):
    return self.name


class Author(models.Model):
  name = models.CharField(max_length=30,verbose_name='姓名')
  age = models.IntegerField(verbose_name='年龄')
  email = models.EmailField(null=True,verbose_name='邮件')

  def __str__(self):
      return self.name

  class Meta:
    db_table = 'author'
    verbose_name = '用户表'
    verbose_name_plural = verbose_name


class Book(models.Model):
  title = models.CharField(max_length=50)
  publicate_date = models.DateField()
  #增加对Publisher的引用(1:M)
  publisher = models.ForeignKey(Publisher,default='1')
  #增加对Author的引用(M:N)
  authors = models.ManyToManyField(Author)

  def __str__(self):
    return self.title


class Wife(models.Model):
  name = models.CharField(max_length=30,verbose_name='姓名')
  age = models.IntegerField(verbose_name='年龄')
  #引用Author,实现一对一映射
  author = models.OneToOneField(Author,verbose_name='相公')

  def __str__(self):
    return self.name


class Img(models.Model):
  img = models.ImageField(upload_to='static/img')
  name = models.CharField(max_length=120)

  def __str__(self):
    return self.name